package com.rd.sys.common.web.session;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * <pre>
 * 类的名称: SessionUtil
 * 描述信息: 
 * 
 * author  
 * ersion 1.0
 * 
 * 完成日期: 2011-6-1
 * </pre>
 */
public class SessionUtil {

    private static SessionManager sessionManager = null;
    private static Logger log = LoggerFactory.getLogger(SessionUtil.class);
    static {
        log.info("Create single session!");
        sessionManager = new SingleSessionManager();
    }

    /**
     * 获取session
     * 
     * @param request
     * @return
     */
    public static HttpSession getSession(HttpServletRequest request) throws Exception {
        return sessionManager.getSession(request);
    }

    /**
     * 获取session
     * 
     * @param request
     * @return
     */
    public static HttpSession getSession(HttpServletRequest request, boolean createSessionWhenNull) throws Exception {
        HttpSession session = sessionManager.getSession(request);
        if (null == session && createSessionWhenNull) {
            session = sessionManager.createSession(request, null, null);
        }
        return session;
    }

    /**
     * 销毁session
     * 
     * @param request
     * @return
     */
    public static void destorySession(HttpServletRequest request) throws Exception {
        sessionManager.destorySession(request);
    }

    /**
     * 创建session
     * 
     * @param request
     * @return
     */
    public static void createSession(HttpServletRequest request, String key, Object value) throws Exception {
        sessionManager.createSession(request, key, value);
    }
}

/**
 * 文件结束: SessionUtil.java
 */
